#ifndef __THREAD_HPP__
#define __THREAD_HPP__

#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <pthread.h>

typedef void*(*func_t)(void*);

struct ThreadData
{
    std::string _name;
    void* _args;
};

class Thread
{
public:
    Thread(int num,func_t callback,void* args)
        :_num(num)
        ,_fun(callback)
    {
        char buff[64];
        memset(buff,0,sizeof(buff));
        snprintf(buff,sizeof(buff),"Thread-%d",_num);
        _name=buff;

        _td._name=_name;
        _td._args=args;
    }

    void create()
    {
        pthread_create(&_tid,nullptr,_fun,(void*)&_td);
    }

    void join()
    {
        pthread_join(_tid,nullptr);
    }

    ~Thread()
    {}
private:
    pthread_t _tid;//线程
    int _num;//重铸线程ID
    std::string _name;//线程名
    func_t _fun;//线程执行流函数
    ThreadData _td;//线程数据
};

#endif